<template>
	<div class="aid">
		<div class="base">
			<p class="fixed-top">
				<span>{{ linktype == 1 ? '详情' : linktype == 2 ? '修改权限' : linktype == 3 ? '设为管理员' : '取消管理员' }}</span>
				<a-icon @click="closeFunction" type="close" />
			</p>
			<div class="main" id="new_message">
				<a-form :form="form">
					<a-form-item label="学号" >{{ text.UserNo }}</a-form-item>
					<a-form-item label="发起活动权限" >
						<a-radio-group name="radioGroup" @change="radioOnChange" :disabled="linktype == 1" v-decorator="['IsAgreeApplyActivity', { rules: [{ required: true, message: '请选择发起活动权限' }] }]">
							<a-radio :value="true">是</a-radio>
							<a-radio :value="false">否</a-radio>
						</a-radio-group>
					</a-form-item>
					<a-form-item label="管理成员权限" >
						<a-radio-group name="radioGroup1" @change="radioOnChange" :disabled="linktype == 1" v-decorator="['IsAgreeManageMember', { rules: [{ required: true, message: '请选择管理成员权限' }] }]">
							<a-radio :value="true">是</a-radio>
							<a-radio :value="false">否</a-radio>
						</a-radio-group>
					</a-form-item>
					<a-form-item class="fixed-bottom">
					
						<a-button v-if="linktype != 1" type="primary"  @click="handleSubmit">
							提交
						</a-button>
					</a-form-item>
					<!-- <a-form-item class="fixed-bottom" v-if="linktype != 1"><a-button type="primary" html-type="submit" class="btn2">提交</a-button></a-form-item> -->
				</a-form>
			</div>
		</div>
	</div>
</template>
<script>
import Cache from '@/utils/cache';
import { DoUpdateUserClubMember, DoGetDetailUserClubMember, DoAddUserClubMember } from '@/api/follow';
export default {
	props: {
		text: Object,
	},
	watch: {
		text: {
			handler(text) {
				this.linktype = text.linktype
				if (text.linktype == 1 || text.linktype == 2) {
					this.GetConfirmState();
				} else {
					this.form.resetFields();
				}
			},
			immediate: true
		}
	},
	data() {
		return {
			formLayout: 'horizontal',
			form: this.$form.createForm(this, {
				name: 'coordinated'
			})
		};
	},
	async created() {
		// await this.GetConfirmState()
	},
	methods: {
		async GetConfirmState() {
			if (this.linktype == 1 || this.linktype == 2) {
				let data = {};
				data.clubID = this.text.ID;
				data.userNo = this.text.UserNo;
				let res = await DoGetDetailUserClubMember(data);
				if (res.data.code == 0) {
					this.form.setFieldsValue({
						IsAgreeApplyActivity: res.data.data.IsAgreeApplyActivity,
						IsAgreeManageMember: res.data.data.IsAgreeManageMember
					});
				}
			}
		},
		radioOnChange(e) {},
		filterOption(input, option) {
			return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0;
		},
		closeFunction(data) {
			this.worklist = [];
			this.form.resetFields();
			this.$emit('closeFun',data);
		},
		roleChange(value) {},
		departmentChange(value) {},
		handleSubmit(e) {
			let data = {};
			this.form.validateFields(async (err, values) => {
				if (!err){
					data.ID = this.text.ManagerID;
					data.ClubID = this.text.ID;
					data.UserNo = this.text.UserNo;
					data.IsAgreeApplyActivity = values.IsAgreeApplyActivity;
					data.IsAgreeManageMember = values.IsAgreeManageMember;
					// if(!data.IsAgreeApplyActivity&&!data.IsAgreeManageMember){
					// 	return false
					// }
					let res={}
					if (this.linktype == 2) {
						res = await DoUpdateUserClubMember(data);
					}else{
						res = await DoAddUserClubMember(data);
					}
					if (res.data.code === 0) {
						this.$message.success(res.data.msg);
						this.closeFunction(1)
					} else {
						this.$message.error(res.data.msg);
					}
				}
			})
		}
	}
};
</script>

<style lang="less" scoped>
.aid {
	position: fixed;
	width: 100%;
	height: 100%;
	background: rgba(0, 0, 0, 0.5);
	top: 0px;
	left: 0px;
	z-index: 999;
}

.base {
	position: absolute;
	width: 600px;
	// height: 540px;
	height: auto;
	background: #fff;
	left: 50%;
	margin-left: -300px;
	top: 50%;
	margin-top: -270px;
	overflow-y: auto;
}
.main {
	height: 90%;
	overflow-y: scroll;
}

/deep/.ant-form-item {
	margin: 20px 50px;
	display: flex;
}
/deep/.ant-form-item-label {
	width: 120px;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
	text-align: right;
}

/deep/.ant-form-item-control-wrapper {
	flex: 1;
}
/deep/.ant-calendar-picker,
/deep/.ant-time-picker {
	width: 100%;
}
.fixed-top {
	width: inherit;
	position: absolute;
	line-height: 30px;
	top: 0px;
	background-color: white;
	z-index: 999;
	padding: 10px 0 0 10px;
}

.fixed-bottom {
	width: 164px;
	left: 50%;
	bottom: 0px;
	margin: 0px 0px 0px -82px !important;
	position: absolute;
	background-color: white;
	z-index: 999;
}

/deep/.ant-form {
	margin-top: 50px;
	padding-bottom: 50px;
}
</style>
